<?php
class ProvincieController extends AdminController{
	public function actionIndex(){
		$mP = new Mapper_Provincie();
		$this->provincies = $mP->getAll();
	}

	public function actionAdd(){
		if($this->request->isPost()){
			$mP = new Mapper_Provincie();

			$provincie = new Provincie();
			if($provincie = $this->request->createFromPost($provincie)){
				if($mP->insert($provincie)){
					$this->redirect($this->module, $this->controller);
				}
			}
		}
	}

	public function actionRemove(){
		if($this->request->hasParam("provincie_id")){
			$mP = new Mapper_Provincie();

			$this->provincie = $mP->get($this->request->getParam("provincie_id"));

			if($this->provincie->IsInUse){
				$this->redirect($this->module, $this->controller);
			}

			if($this->request->hasParam("confirm")){
				try{
					if($mP->remove($this->provincie)){
						$this->redirect($this->module, $this->controller);
					}
				}catch(Exception $e){

				}
			}
		}else{
			$this->redirect($this->module, $this->controller);
		}
	}

	public function actionEdit(){
		if($this->request->hasParam("provincie_id")){
			$mP = new Mapper_Provincie();

			$this->provincie = $mP->get($this->request->getParam("provincie_id"));

			if($this->request->isPost()){
				$provincie = $this->request->createFromPost($this->provincie);

				if($mP->update($provincie)){
					$this->redirect($this->module, $this->controller);
				}
			}
		}else{
			$this->redirect($this->module, $this->controller);
		}
	}
}